<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <script type="text/babel">
        // class Sub extends React.Component{
        //     constructor(){
        //         super();
        //         this.input = React.createRef();
        //     }
        //     render(){
        //         return <div>
        //             <input ref={this.input} type="text" />
        //         </div>
        //     }
        // }
        // class Parent extends React.Component{
        //     constructor(){
        //         super();
        //         this.input = React.createRef();
        //     }
        //     handleClick = () => {
        //         console.log(this.input.current.input.current.value);
        //     }
        //     render(){
        //         return <div>
        //             <Sub ref={this.input}></Sub>
        //             <input type="button" onClick={this.handleClick} value="OK" />
        //         </div>
        //     }
        // }

        let Sub = React.forwardRef(function(props,ref){
            
            return <div>
                    <input ref={ref} type="text" />
                </div>
        })
        let Parent = function(props){
            let input = React.createRef();
            let handleClick = () => {
                console.log(input.current.value);
            }
            return <div>
                <Sub ref={input}></Sub>
                <input type="button" onClick={() => handleClick} value="OK" />
            </div>
        }
        ReactDOM.render(<Parent />,document.getElementById("root"));
    </script>
</body>
</html>